using System;
using System.Collections.Generic;
using System.Text;



using CreamX.Framework.Game.Components;
using CreamX.Framework.Game;
using CreamX.Framework.Attributes;

namespace CreamXComponentPack
{
    [CreamXComponentAttribute("EmitterComponent")]
    public class EmitterComponent:CreamXComponent
    {
        private int _currentCount;
        private string _object;
        private float _rate;
        private float _count;
        public float _timer = 0;
        
        public EmitterComponent()
        {
        }

        public override void OnRegister()
        {
            Enabled = true;
            base.OnRegister();
        }

        [CreamXComponentProperty("ObjectToEmit")]
        public string ObjectToEmit
        {
            get { return _object; }
            set { _object = value; }
        }
        
        [CreamXComponentProperty("Rate")]
        public float Rate
        {
            get { return _rate; }
            set { _rate = value; }
        }
        
        [CreamXComponentProperty("Count")]
        public float Count
        {
            get { return _count; }
            set { _count = value; }
        }
        
        public int CurrentCount
        {
            get { return _currentCount; }
            set { _currentCount = value; }
        }

        public override void Update(float elapsed)
        {
            if (CurrentCount < Count)
            {
                _timer += elapsed;
                if (_timer > _rate)
                {
                    _timer = 0;
                    CreamXObject __ob = CurrentScene.CreateClone(ObjectToEmit);
                    CurrentScene.RegisterObject(__ob);
                    __ob.SetPosition(SceneObject.Position);
                    CurrentCount++;
                }
            }
            base.Update(elapsed);
        }
    }
}
